#include <cstdlib>
#include <iostream>
#include <fstream>
#include "functions.h"
#include "80disasm.h"


_80disasm::_80disasm(int * memory,int file_size)
{
                         
                    export_to_file=false;
                    output="";
                    size=file_size;
                    ptr=0;
                    this->MEMORY=memory;           
                    
}



std::string _80disasm::getOutput()
{
 
 return output;
 
            
}

void _80disasm::setExport(bool v)
{
      export_to_file=v;                    
}

_80disasm::~_80disasm()
{

delete[] MEMORY;
            
}


void _80disasm::exec()
{
     

     
     if(export_to_file)
     pFile = fopen ("output.asm","w");

     
                  
                 while(ptr<size)
                 {
                 
                          
                          fetch(MEMORY[ptr]);
                          
                            
                          if(export_to_file)
                           fputs (temp,pFile);
    

 
                } 
if(export_to_file)          
fclose (pFile);        
                
                      
                  
}



void _80disasm::fetch(int opcode)
{

        
              int n=0; 
        switch(opcode)
        {
                
                
                
         case 0x00: // NOP
         
               n=sprintf(temp,"NOP\n");
               output+=temp;
              ptr++;
              break;
         
         
         
              
               case 0x01: //LXI B,nn
               n=sprintf(temp,"LXI B, %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
               output+=temp;
                ptr+=3;
                break;
                
              
               
              
               case 0x02:
               n=sprintf(temp,"STAX B,A\n");
               output+=temp;
               ptr++;           
               break;
               
               
               case 0x03:
               
               n=sprintf(temp,"INX B\n");
               output+=temp;
               ptr++;           
               break;
               
               
               case 0x04:
               n=sprintf(temp,"INR B\n");
               output+=temp;
               ptr++;
                break;
                
                
                case 0x05:
                 n=sprintf(temp,"DCR B\n");
                 output+=temp;
                ptr++;
                break;
                
                
               case 0x06:
                    n=sprintf(temp,"MVI B,%xh\n",MEMORY[ptr+1]);
                    output+=temp;
                    ptr+=2;
               break;
                case 0x07:
                     n=sprintf(temp,"RLC\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x09:
                    n=sprintf(temp,"DAD B\n");
                    output+=temp;
                     ptr++;
                break;
                
                
                case 0x0A:
                     n=sprintf(temp,"LDAX B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x0B:
                     n=sprintf(temp,"DCX B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0X0C:
                     n=sprintf(temp,"INR C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x0D:
                     n=sprintf(temp,"DCR C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x0E:
                     n=sprintf(temp,"MVI C,%xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                case 0x0F:
                     n=printf(temp,"RRC\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x11:
                     n=sprintf(temp,"LXI D,%x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                case 0x12:
                     n=sprintf(temp,"STAX D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x13:
                     n=sprintf(temp,"INX D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x14:
                    n=sprintf(temp,"INR D\n");
                    output+=temp;
                     ptr++;
                break;
                
                
                case 0x15:
                     n=sprintf(temp,"DCR D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x16:
                     n=sprintf(temp,"MVI D,%xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                case 0x17:
                     n=sprintf(temp,"RAL\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x19:
                     n=sprintf(temp,"DAD D\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x1A:
                     n=sprintf(temp,"LDAX D\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x1B:
                     n=sprintf(temp,"DCX D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x1C:
                     n=sprintf(temp,"INR E\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0x1D:
                     n=sprintf(temp,"DCR E\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x1E:
                     n=sprintf(temp,"MVI E,%xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                case 0x1F:
                     n=sprintf(temp,"RAR\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x21:
                     n=sprintf(temp,"LXI H,%x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                case 0x22:
                     n=sprintf(temp,"SHLD %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                case 0x23:
                     n=sprintf(temp,"INX H\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x24:
                     n=sprintf(temp,"INR H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x25:
                     n=sprintf(temp,"DCR H\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x26:
                     n=sprintf(temp,"MVI H,%xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                case 0x27:
                     n=sprintf(temp,"DAA\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x29:
                     n=sprintf(temp,"DAD H\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x2A:
                     n=sprintf(temp,"LHLD %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                case 0x2B:
                     n=sprintf(temp,"DCX H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x2C:
                     n=sprintf(temp,"INR L\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x2D:
                     n=sprintf(temp,"DCR L\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x2E:
                     n=sprintf(temp,"MVI L,%xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                case 0x2F:
                     n=sprintf(temp,"CMA\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x31:
                     n=sprintf(temp,"LXI SP,%x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                case 0x32:  
                     n=sprintf(temp,"STA %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                case 0x33:
                     n=sprintf(temp,"INX SP\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x34:
                     n=sprintf(temp,"INR M\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x35:
                     n=sprintf(temp,"DCR M\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x36:
                     n=sprintf(temp,"MVI M,%xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                case 0x37:
                     n=sprintf(temp,"STC\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x39:
                     n=sprintf(temp,"DAD SP\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x3A:
                     n=sprintf(temp,"LDA %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                case 0x3B:
                     n=sprintf(temp,"DCX SP\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x3C:
                     n=sprintf(temp,"INR A\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x3D:
                     n=sprintf(temp,"DCR A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x3E:
                     n=sprintf(temp,"MVI A,%xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                
                case 0x3F:
                     n=sprintf(temp,"CMC\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x40:
                     n=sprintf(temp,"MOV B,B\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x41:
                      n=sprintf(temp,"MOV B,C\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x42:
                      n=sprintf(temp,"MOV B,D\n");
                     output+=temp;
                     ptr++;
                break;
                     
                case 0x43:
                     n=sprintf(temp,"MOV B,E\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x44:
                     n=sprintf(temp,"MOV B,H\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x45:
                     n=sprintf(temp,"MOV B,L\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x46:
                     n=sprintf(temp,"MOV B,M\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x47:
                     n=sprintf(temp,"MOV B,A\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x48:
                     n=sprintf(temp,"MOV C,B\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x49:
                     n=sprintf(temp,"MOV C,C\n");
                     output+=temp;
                     ptr++;
                break; 
                
                case 0x4A:
                     n=sprintf(temp,"MOV C,D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x4B:
                     n=sprintf(temp,"MOV C,E\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x4C:
                     n=sprintf(temp,"MOV C,H\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x4D:
                     n=sprintf(temp,"MOV C,L\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x4E:
                     n=sprintf(temp,"MOV C,M\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x4F:
                     n=sprintf(temp,"MOV C,A\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x50:
                     n=sprintf(temp,"MOV D,B\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x51:
                     n=sprintf(temp,"MOV D,C\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x52:
                     n=sprintf(temp,"MOV D,D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x53:
                     n=sprintf(temp,"MOV D,E\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x54:
                     n=sprintf(temp,"MOV D,H\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x55:
                     n=sprintf(temp,"MOV D,L\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x56:
                     n=sprintf(temp,"MOV D,M\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x57:
                     n=sprintf(temp,"MOV D,A\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x58:
                     n=sprintf(temp,"MOV E,B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x59:
                     n=sprintf(temp,"MOV E,C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x5A:
                     n=sprintf(temp,"MOV E,D\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x5B:
                     n=sprintf(temp,"MOV E,E\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x5C:
                     n=sprintf(temp,"MOV E,H\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x5D:
                     n=sprintf(temp,"MOV E,L\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x5E:
                     n=sprintf(temp,"MOV E,M\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x5F:
                     n=sprintf(temp,"MOV E,A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x60:
                     n=sprintf(temp,"MOV H,B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0x61:
                     n=sprintf(temp,"MOV H,C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0x62:
                     n=sprintf(temp,"MOV H,D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x63:
                     n=sprintf(temp,"MOV H,E\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x64:
                     n=sprintf(temp,"MOV H,H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0x65:
                     n=sprintf(temp,"MOV H,L\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0x66:
                     n=sprintf(temp,"MOV H,M\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0x67:
                     n=sprintf(temp,"MOV H,A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                
                case 0x68:
                     n=sprintf(temp,"MOV L,B\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x69:
                     n=sprintf(temp,"MOV L,C\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x6A:
                     n=sprintf(temp,"MOV L,D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x6B:
                     n=sprintf(temp,"MOV L,E\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x6C:
                     n=sprintf(temp,"MOV L,H\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x6D:
                     n=sprintf(temp,"MOV L,L\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x6E:
                     n=sprintf(temp,"MOV L,M\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0x6F:
                     n=sprintf(temp,"MOV L,A\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x70:
                     n=sprintf(temp,"MOV M,B\n");
                     output+=temp;
                     ptr++;
                break;
                    
                    
                    case 0x71:
                     n=sprintf(temp,"MOV M,C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                 case 0x72:
                     n=sprintf(temp,"MOV M,D\n");
                     output+=temp;
                     ptr++;
                break; 
                
                
                
                 case 0x73:
                     n=sprintf(temp,"MOV M,E\n");
                     output+=temp;
                     ptr++;
                break;
                
                 case 0x74:
                     n=sprintf(temp,"MOV M,H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                 case 0x75:
                     n=sprintf(temp,"MOV M,L\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                 case 0x76:
                     n=sprintf(temp,"HLT\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                 case 0x77:
                     n=sprintf(temp,"MOV M,A\n");
                     output+=temp;
                     ptr++;
                break;
                
                 case 0x78:
                     n=sprintf(temp,"MOV A,B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x79:
                     n=sprintf(temp,"MOV A,C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x7A:
                     n=sprintf(temp,"MOV A,D\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x7B:
                     n=sprintf(temp,"MOV A,E\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x7C:
                     n=sprintf(temp,"MOV A,H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x7D:
                     n=sprintf(temp,"MOV A,L\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x7E:
                     n=sprintf(temp,"MOV A,M\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x7F:
                     n=sprintf(temp,"MOV A,A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x80:
                     n=sprintf(temp,"ADD B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0x81:
                     n=sprintf(temp,"ADD C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x82:
                     n=sprintf(temp,"ADD D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0x83:
                     n=sprintf(temp,"ADD E\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x84:
                     n=sprintf(temp,"ADD H\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x85:
                     n=sprintf(temp,"ADD L\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x86:
                     n=sprintf(temp,"ADD M\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0x87:
                     n=sprintf(temp,"ADD A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0x88:
                     n=sprintf(temp,"ADC B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                
                 case 0x89:
                     n=sprintf(temp,"ADC C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                 case 0x8A:
                     n=sprintf(temp,"ADC D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                 case 0x8B:
                     n=sprintf(temp,"ADC E\n");
                     output+=temp;
                     ptr++;
                break;
                
                 case 0x8C:
                     n=sprintf(temp,"ADC H\n");
                     output+=temp;
                     ptr++;
                break;
                
                 case 0x8D:
                     n=sprintf(temp,"ADC L\n");
                     output+=temp;
                     ptr++;
                break;
                
                 case 0x8E:
                     n=sprintf(temp,"ADC M\n");
                     output+=temp;
                     ptr++;
                break;
                
                 case 0x8F:
                     n=sprintf(temp,"ADC A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                 case 0x90:
                     n=sprintf(temp,"SUB B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                  case 0x91:
                     n=sprintf(temp,"SUB C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                  case 0x92:
                     n=sprintf(temp,"SUB D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                  case 0x93:
                     n=sprintf(temp,"SUB E\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                  case 0x94:
                     n=sprintf(temp,"SUB H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                
                  case 0x95:
                     n=sprintf(temp,"SUB L\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                  case 0x96:
                     n=sprintf(temp,"SUB M\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                  case 0x97:
                     n=sprintf(temp,"SUB A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                  case 0x98:
                     n=sprintf(temp,"SBB B\n");
                     output+=temp;
                     ptr++;
                break;
                
                  case 0x99:
                     n=sprintf(temp,"SBB C\n");
                     output+=temp;
                     ptr++;
                break;
                
                  case 0x9A:
                     n=sprintf(temp,"SBB D\n");
                     output+=temp;
                     ptr++;
                break;
                
                  case 0x9B:
                     n=sprintf(temp,"SBB E\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                  case 0x9C:
                     n=sprintf(temp,"SBB H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                  case 0x9D:
                     n=sprintf(temp,"SBB L\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                  case 0x9E:
                     n=sprintf(temp,"SBB M\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                  case 0x9F:
                     n=sprintf(temp,"SBB A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                 case 0xA0:
                     n=sprintf(temp,"ANA B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xA1:
                     n=sprintf(temp,"ANA C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xA2:
                     n=sprintf(temp,"ANA D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xA3:
                     n=sprintf(temp,"ANA E\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xA4:
                     n=sprintf(temp,"ANA H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xA5:
                     n=sprintf(temp,"ANA L\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xA6:
                     n=sprintf(temp,"ANA M\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xA7:
                     n=sprintf(temp,"ANA A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xA8:
                     n=sprintf(temp,"XRA B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xA9:
                     n=sprintf(temp,"XRA C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0xAA:
                     n=sprintf(temp,"XRA D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xAB:
                     n=sprintf(temp,"XRA E\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0xAC:
                     n=sprintf(temp,"XRA H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0xAD:
                     n=sprintf(temp,"XRA L\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xAE:
                     n=sprintf(temp,"XRA M\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0xAF:
                     n=sprintf(temp,"XRA A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                
                
                case 0xB0:
                     n=sprintf(temp,"ORA B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0xB1:
                     n=sprintf(temp,"ORA C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xB2:
                     n=sprintf(temp,"ORA D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0xB3:
                     n=sprintf(temp,"ORA E\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0xB4:
                     n=sprintf(temp,"ORA H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xB5:
                     n=sprintf(temp,"ORA L\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0xB6:
                     n=sprintf(temp,"ORA M\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                
                case 0xB7:
                     n=sprintf(temp,"ORA A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0xB8:
                     n=sprintf(temp,"CMP B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                  case 0xB9:
                     n=sprintf(temp,"CMP C\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                  case 0xBA:
                     n=sprintf(temp,"CMP D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                  case 0xBB:
                     n=sprintf(temp,"CMP E\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                  case 0xBC:
                     n=sprintf(temp,"CMP H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                  case 0xBD:
                     n=sprintf(temp,"CMP L\n");
                     output+=temp;
                     ptr++;
                break;
                
                  case 0xBE:
                     n=sprintf(temp,"CMP M\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                  case 0xBF:
                     n=sprintf(temp,"CMP A\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                
                  case 0xC0:
                     n=sprintf(temp,"RNZ\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                 case 0xC1:
                     n=sprintf(temp,"POP B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                 case 0xC2:
                     n=sprintf(temp,"JNZ %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                 case 0xC3:
                     n=sprintf(temp,"JMP %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                 case 0xC4:
                     n=sprintf(temp,"CNZ %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                case 0xC5:
                     n=sprintf(temp,"PUSH B\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xC6:
                     n=sprintf(temp,"ADI %xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                case 0xC7:
                     n=sprintf(temp,"RST %xh\n",0);
                     output+=temp;
                     ptr++;
                break;
                
                case 0xC8:
                     n=sprintf(temp,"RZ\n");
                     output+=temp;
                     ptr++;
                break;
                
                   case 0xC9:
                     n=sprintf(temp,"RET\n");
                     output+=temp;
                     ptr++;
                break;
                
                   case 0xCA:
                     n=sprintf(temp,"JZ %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                 case 0xCC:
                    n=sprintf(temp,"CZ %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                case 0xCD:
                    n=sprintf(temp,"CALL %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                case 0xCE:
                    n=sprintf(temp,"ACI %xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                case 0xCF:
                    n=sprintf(temp,"RST 1\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0xD0:
                    n=sprintf(temp,"RNC\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0xD1:
                    n=sprintf(temp,"POP D\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0xD2:
                    n=sprintf(temp,"JNC %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                
                 case 0xD3:
                    n=sprintf(temp,"OUT %xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                
                 case 0xD4:
                    n=sprintf(temp,"CNC %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                
                 case 0xD5:
                    n=sprintf(temp,"PUSH D\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                 case 0xD6:
                    n=sprintf(temp,"SUI %xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                 case 0xD7:
                    n=sprintf(temp,"RST 2\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                 case 0xD8:
                    n=sprintf(temp,"RC\n");
                     output+=temp;
                     ptr++;
                break;
                
                  case 0xDA:
                   n=sprintf(temp,"JC %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;;
                break;
                
                 case 0xDB:
                    n=sprintf(temp,"IN %xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                 case 0xDC:
                   n=sprintf(temp,"CC %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                 case 0xDE:
                   n=sprintf(temp,"SBI %xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                 case 0xDF:
                   n=sprintf(temp,"RST 3\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0xE0:
                   n=sprintf(temp,"RPO\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xE1:
                   n=sprintf(temp,"POP H\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xE2:
                   n=sprintf(temp,"JPO %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                case 0xE3:
                   n=sprintf(temp,"XTHL\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0xE4:
                   n=sprintf(temp,"CPO %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                  case 0xE5:
                   n=sprintf(temp,"PUSH H\n");
                     output+=temp;
                     ptr++;
                break;
                
                  case 0xE6:
                   n=sprintf(temp,"ANI %xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                
                  case 0xE7:
                   n=sprintf(temp,"RST 4\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                  case 0xE8:
                   n=sprintf(temp,"RPE\n");
                     output+=temp;
                     ptr++;
                break;
                
                  case 0xE9:
                   n=sprintf(temp,"PCHL\n");
                     output+=temp;
                     ptr++;
                break;
                
                  case 0xEA:
                   n=sprintf(temp,"JPE %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                
                case 0xEB:
                   n=sprintf(temp,"XCHG\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xEC:
                   n=sprintf(temp,"CPE %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                case 0xEE:
                   n=sprintf(temp,"XRI %xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                case 0xEF:
                   n=sprintf(temp,"RST 5\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xF0:
                   n=sprintf(temp,"RP\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0xF1:
                   n=sprintf(temp,"POP PSW\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xF2:
                   n=sprintf(temp,"JP %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                
                case 0xF3:
                   n=sprintf(temp,"DI\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0xF4:
                   n=sprintf(temp,"CP %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                case 0xF5:
                   n=sprintf(temp,"PUSH PSW\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xF6:
                   n=sprintf(temp,"ORI %xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                case 0xF7:
                   n=sprintf(temp,"RST 6\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                
                case 0xF8:
                   n=sprintf(temp,"RM\n");
                     output+=temp;
                     ptr++;
                break;
                
                case 0xF9:
                   n=sprintf(temp,"SPHL\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                
                case 0xFA:
                   n=sprintf(temp,"JM %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                case 0xFB:
                   n=sprintf(temp,"EI\n");
                     output+=temp;
                     ptr++;
                break;
                
                
                case 0xFC:
                   n=sprintf(temp,"CM %x%xh\n",MEMORY[ptr+2],MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=3;
                break;
                
                
                case 0xFE:
                   n=sprintf(temp,"CPI %xh\n",MEMORY[ptr+1]);
                     output+=temp;
                     ptr+=2;
                break;
                
                
                case 0xFF:
                   n=sprintf(temp,"RST 7\n");
                     output+=temp;
                     ptr++;
                break;
                
                default:
                n=sprintf(temp,"\nInvalid instruction [ 0x%x ] at adress 0x%x\n",MEMORY[ptr],ptr);
                output=temp;
                ptr=size+1;
                break;
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
        }   
               
                     
                  
                  
}
